package com.ie.sevice.admin.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ie.entity.OrdersEntity;
import com.ie.mapper.admin.OrderMapper;
import com.ie.sevice.admin.OrderService;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

@Service // 标记为 Spring 服务
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrdersEntity> implements OrderService {

    @Override
    public Map<String, Object> getOrdersByUid(Long bUserId, Integer pageNum, Integer pageSize) {
        // 1. 创建分页对象（PageSize 按需求设，这里用流程图的 5）
        IPage<OrdersEntity> page = new Page<>(pageNum, pageSize);

        // 2. 创建条件构造器，添加“等于 BUser ID”条件
        LambdaQueryWrapper<OrdersEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrdersEntity::getBUserId, bUserId); // 只查当前用户的订单

        // 3. 执行分页查询
        IPage<OrdersEntity> resultPage = baseMapper.selectPage(page, wrapper);

        // 4. 构造返回结果 Map
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("ordersByUid", resultPage.getRecords()); // 订单列表
        resultMap.put("totalPage", resultPage.getPages());     // 总页数

        return resultMap;
    }
}